package com.kk.stringapi;

/**
 * @author MH
 * @date 2022-01-17
 */
public class StringTrim {
    public static void main(String[] args) {

        String s = " 12  3 ";

        // trim() 去掉字符串两端的空格，无论空格有多少个都会去掉，中间的空格不会去掉
        String trimRes = s.trim();
        System.out.println("trim() after:" + trimRes);

        // replace \ replaceAll 都是全部替换，不同点：replaceAll-支持正则表达式
        String replace = s.replace(" ", "");
        System.out.println("replace() after:" + replace);

        String replaceAll = s.replaceAll("[\\s]{2}", "");
        System.out.println("replaceAll() after:" + replaceAll);
    }
}
